package world.hezi.handlers;

import net.mamoe.mirai.contact.Contact;
import net.mamoe.mirai.event.EventHandler;
import net.mamoe.mirai.event.ListeningStatus;
import net.mamoe.mirai.event.SimpleListenerHost;
import net.mamoe.mirai.event.events.MessageEvent;
import net.mamoe.mirai.message.data.MessageChain;
import net.mamoe.mirai.message.data.MessageChainBuilder;
import org.jetbrains.annotations.NotNull;
import world.hezi.utils.LinuxCommandUtil;
import world.hezi.utils.PicturesUtil;

import java.util.List;
import java.util.Objects;
import java.util.Scanner;

/**
 * @author wangzijian
 * @since 2023/11/13 15:38
 */
public class LinuxCommandHandlers extends SimpleListenerHost {
    @NotNull
    @EventHandler
    public ListeningStatus onMessage(@NotNull MessageEvent event) throws Exception {

        if (event.getSender().getId() == 651343119L){
            String message = event.getMessage().contentToString();
            if (message.indexOf("/exec ") != 0){
                return ListeningStatus.LISTENING;
            }
            message = message.substring(6);
            List<String> list = LinuxCommandUtil.execCommand(message);
            MessageChainBuilder messages = new MessageChainBuilder();
            for (String s : list) {
                messages.append(s).append("\n");
            }
            Contact contact = event.getSubject();
            contact.sendMessage(messages.build());
        }
        return ListeningStatus.LISTENING;
    }
}
